using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using Lucene.Net.Documents;

namespace FutureOpen.Core.func.index
{
    public class ConfigSectionField : ConfigurationSection
    {
        [ConfigurationProperty("Name")]
        public string Name
        {
            get { return (string)this["Name"]; }
            set { this["Name"] = value; }
        }

        [ConfigurationProperty("Index")]
        public string Index
        {

            get { return (string)this["Index"]; }
            set { this["Index"] = value; }
        }
        
        [ConfigurationProperty("Store")]
        public string Store
        {

            get { return (string)this["Store"]; }
            set { this["Store"] = value; }
        }

        [ConfigurationProperty("TermVector")]
        public string TermVector
        {
            get { return (string)this["TermVector"]; }
            set { this["TermVector"] = value; }
        }
        public override string ToString()
        {
            return "Name=" + Name + ",Index=" + Index + ",Store=" + Store + ",TermVector=" + TermVector;
        }

        
        public void setValues(string name,Field.Index index,Field.Store store,Field.TermVector vector)
        {
            Name = name;
            Store = store.ToString();
            Index = index.ToString();
            TermVector = vector.ToString();
        }

        public Field getLuceneField(string value)
        {
            Field.Store store = null;
            Field.Index index = null;
            Field.TermVector vector = null;

            if(Index.Equals(Field.Index.NO.ToString()))
                index = Field.Index.NO;
            else if(Index.Equals(Field.Index.NO_NORMS.ToString()))
                index = Field.Index.NO_NORMS;
            else if(Index.Equals(Field.Index.TOKENIZED.ToString()))
                index = Field.Index.TOKENIZED;
            else if(Index.Equals(Field.Index.UN_TOKENIZED.ToString()))
                index = Field.Index.UN_TOKENIZED;

            //if (Store.Equals(Field.Store.COMPRESS.ToString()))
            //    store = Field.Store.COMPRESS;
            //else if (Store.Equals(Field.Store.NO.ToString()))
            //    store = Field.Store.NO;
            //if (Store.Equals(Field.Store.YES.ToString()))
                store = Field.Store.YES;

            if (TermVector.Equals(Field.TermVector.NO.ToString()))
                vector = Field.TermVector.NO;
            else if (TermVector.Equals(Field.TermVector.WITH_OFFSETS.ToString()))
                vector = Field.TermVector.WITH_OFFSETS;
            else if (TermVector.Equals(Field.TermVector.WITH_POSITIONS.ToString()))
                vector = Field.TermVector.WITH_POSITIONS;
            else if (TermVector.Equals(Field.TermVector.WITH_POSITIONS_OFFSETS.ToString()))
                vector = Field.TermVector.WITH_POSITIONS_OFFSETS;
            else if (TermVector.Equals(Field.TermVector.YES.ToString()))
                vector = Field.TermVector.YES;

            Field f = new Field(Name, value, store, index, vector);

            return f;
        }
    }
}
